﻿	<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
	<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
	<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants" %>

	<script type="text/javascript">
		var hideAuthPanelAfterSelect = function() 
		{
			var auths = $('#dlg-role #fm-role #authority').combotree('getValues');
			$('#dlg-role #fm-role #authorities').val(auths);
		}
		var cellFormatter_roleAuthority = function(value,row,index)
		{
			var auths = '';
			if(row.authorityBeans)
			{
				if(row.authorityBeans.length >= 1) 
				{
					for(var i = 0; i < row.authorityBeans.length; i++) 
					{
						auths += (row.authorityBeans[i].name + ',');
					}
					auths = auths.substring(0, auths.length - 1);
				}
			}
			return '<a href="#" title="' + auths + '" class="easyui-tooltip" style="text-decoration: none">' + auths + '</a>';
		}
		var editRoleCallback = function() 
		{
			var role = $('#dg-role').datagrid('getSelected');
			if(role) 
			{
				var auths = role.authorityBeans;
				if(auths && auths.length > 0) 
				{
					var authIds = new Array(auths.length);
					for(var i = 0; i < auths.length; i ++) 
					{
						authIds[i] = auths[i].id;
					}
					$('#dlg-role #fm-role #authority').combotree('setValues', authIds);
					hideAuthPanelAfterSelect();
				}
				
				if(role.enable) 
				{
					$('#dlg-role #fm-role #enable')[0].checked = true;
				}
				else 
				{
					$('#dlg-role #fm-role #enable')[0].checked = false;
				}
				if(role.system) 
				{
					$('#dlg-role #fm-role #system')[0].checked = true;
				}
				else 
				{
					$('#dlg-role #fm-role #system')[0].checked = false;
				}
			}
		}
    </script>
	
	<table id="dg-role" title="角色管理" class="easyui-datagrid" url="<c:url value='/role/getAllRole.html' />"
		toolbar="#toolbar-role" rownumbers="true" fit="true"
		 singleSelect="true" checkOnSelect="true" selectOnCheck="false"
		fitColumns="true">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'id',hidden:true"></th>
				<th field="name" width="50" sortable="true">角色名</th>
				<th field="enable" width="50" sortable="true" data-options="formatter:cellFormatter_enable, align:'center'">可用</th>
				<th field="system" width="50" sortable="true" data-options="formatter:cellFormatter_enable, align:'center'">系统账户</th>
				<th field="authority" width="50" sortable="false" data-options="formatter:cellFormatter_roleAuthority, styler:cellStyler_userRole">权限</th>
				<th field="comment" width="100" sortable="false">备注</th>
			</tr>
		</thead>
	</table>
	
	<div id="toolbar-role">
		<a href="javascript:void(0)" class="easyui-linkbutton" 
			iconCls="icon-add" plain="true" onclick="newModel('#dlg-role', '新增角色', '#fm-role', '<c:url value='/role/newRole.html' />')" title="新增角色">新增角色</a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editModel('#dg-role', '#dlg-role', '编辑角色', '#fm-role', '<c:url value='/role/updateRole.html' />', editRoleCallback)" title="<spring:message code="selectOneRow" />编辑角色">编辑角色</a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyMultipleModel('#dg-role', '角色', '<c:url value='/role/delRole.html' />')" title="<spring:message code="checkOneOrMultiple" />删除角色">删除角色</a>
	</div>

	<div id="dlg-role" class="easyui-dialog"
		style="width: 800px; height: 300px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-role" data-options="modal:true">
		<div class="ftitle">角色</div>
		<div style="">
		<form id="fm-role" class="fm" method="post" novalidate>
			<div class="fitem divHidden">
				<input id="roleId" name="id" value="0">
			</div>
			<div class="fitem">
				<label>名称:</label> 
				<input name="name" class="easyui-validatebox" required="true"
				validType="myRemote['<c:url value='/role/checkExist.html' />', 'name', '#roleId']">
			</div>
			<div class="fitem">
				<label>可用:</label> 
				<input id="enable" name="enable" type="checkbox" style="width:20px">
			</div>
			<div class="fitem">
				<label>是否系统:</label> 
				<input id="system" name="system" type="checkbox" style="width:20px">
			</div>
			<div class="fitem">
				<label>权限:</label> 
				<input name="authority" id="authority" class="easyui-combotree" panelHeight="auto"  
					data-options="url:'<c:url value='/authority/getAllAuthority.html' />',required:true, 
					multiple:true, checkbox:true, 
					onHidePanel:hideAuthPanelAfterSelect">
				<input name="authorities" id="authorities" type="hidden" />
			</div>
			<div class="fitem">
				<label>备注:</label> 
				<input name="comment">
			</div>
		</form>
		</div>
	</div>
	<div id="dlg-buttons-role">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-role', '#dlg-role', '#fm-role')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-role').dialog('close')"><spring:message code="cancel" /></a>
	</div>